<?php
// No direct access
defined('_JEXEC') or die;
$items = $this->items;
$catId = JRequest::getVar('id');

$session = JFactory::getSession();
$location = $session->get('location');
?>

<div class="box-header">
	<?php echo (isset($catId)) ? $this->categoryInfo->title : ( ($location) ? $items[0]->location_name : 'Mới nhất' ); ?>
</div>

<ul class="latest-list-images">
	<?php foreach ($items as $item): ?>
	<li>
		<?php 
		require_once JPATH_ROOT . DS . 'jelibs/classes/util.class.php';
		
		/*
		$file 		= JPATH_ROOT . DS . 'images/je_products/upload/' . $item->images;
		$thumbFile 	= JPATH_ROOT . DS . 'images/je_products/thumbs/160/thumb_' . $item->images;
		
		JEUtil::resizeImage($file, $thumbFile, 160);
		*/
		
		$pathUpload = JPATH_ROOT . DS . 'images/je_products/upload/';
		$pathThumb = JPATH_ROOT . DS . 'images/je_products/thumbs/160/';
		
		$thumb = JEUtil::thumb($item->images, $pathUpload, $pathThumb, 160, 60);
		?>				
		
		<?php 
		$session = JFactory::getSession();
		$location = $session->get('location_name', null);
		
		if(!$location || $item->location_name == 'all-location')
			$location = ($item->location_name == 'all-location') ? 'Toàn Quốc' : $item->location_name; 
		?>
		
		<a title="<?php echo $location . ': ' . $item->name; ?>" href="<?php echo JRoute::_(JE_ProductHelperRoute::getDetailRoute($item->id, $item->catid, $item->alias)); ?>">
			<span class="img">
				<img alt="<?php echo $item->alias; ?>" src="images/je_products/thumbs/160/<?php echo $thumb[0]; ?>">
			</span>
			<strong><?php echo $location; ?>:</strong> <?php echo $item->name;?>
			<span class="expire">(Kết thúc: <?php echo date('d/m/Y', strtotime($item->publish_down)); ?>)</span>
		</a>
	</li>
	<?php endforeach; ?>
</ul>

<div class="clr"></div>

<div class="pagination">
	<?php echo $this->pagination->getPagesLinks(); ?>
</div>

<div class="clr"></div>